<?php
require_once $GLOBALS['ROO'] . 'Modules/Operative/class.sender.php';
require_once $GLOBALS['ROO'] . 'Libraries/Pr_db/pr_operative.mex';
require_once($GLOBALS['LNG'] . $_SESSION[$SESSLG] . '/lang.default.mex');
require_once $GLOBALS['ROO'] . 'Modules/Geo/class.geo.php';

$Client = New Sender();

$MDCL = 'RD';
$MDOR = 'ED';
$MD0 = '" disabled readonly="';
$SliLock = '';

if (isset($_GET['CID'])) {
    $OBJCTCL = $_GET['CID'];
} elseif (isset($_POST['OBJCTCL'])) {
    $OBJCTCL = $_POST['OBJCTCL'];
} else {
    $OBJCTCL = 0;
}
$CLST = 0;
$VoucherSimNao = "";
$VoucherNumero = 0;

$Cliente[1] = $Client->GetSender($OBJCTCL);
if ($Cliente[1]['CliBloqueado'] > 0) {
    $CLST = $Cliente[1]['CliBloqueado'];
}
if ($Cliente[1]['CliNumero'] > 0) {
    $action = '_response/call.php?get=Operative/sender';
    echo '<script charset="utf-8" type="text/javascript">replaceUrl(\'leftBar\',\'_response/call.php?get=Operative/client_options&OB=' . $Cliente[1]['CliNumero'] . '&ARC=' . $Cliente[1]['CliHasArchive'] . '&CST=' . $Cliente[1]['CliBloqueado'] . '\');</script>';
} else {
    $action = '_response/call.php?get=Operative/opv_sendernew';
    $MDCL = 'ED';
    $MD0 = '';
    $VWCLDT = 1;
    $_POST['MDCLDT'] = 'True';
}
if ((!isset($_POST['MDCLDT']) || ($_POST['MDCLDT'] == 'True')) && $OBJCTCL > 0) {
    $_POST['MDCLDT'] = 'False';
} else {
    $_POST['MDCLDT'] = 'True';
}
if (!isset($Cliente[1]['OriNombre'])) {
    $Cliente[1]['OriNombre'] = 'Sem balcão atribuído';
}

if ($_POST['MDCLDT'] == 'True' && $Cliente[1]['CliOffice'] == $_SESSION[$SESSCD]) {
    $MDCL = 'ED';
    $MD0 = '';
}
$QurGathers = $GLOBALS['MYT']->db_array("SELECT * FROM unionclientesangariadores WHERE uca_Client = {$OBJCTCL}");
// Check Card
$Ck_Card = $GLOBALS['MYT']->db_array("SELECT car_ID, car_Status, cpr_POrigen, car_Delivered, round(bac_Balance,0) AS bac_Balance FROM bonuscards
		LEFT OUTER JOIN bonusaccounts ON bac_Client = car_Client
	  	LEFT OUTER JOIN bns_printersattrib ON cpr_Origen = car_Office
		WHERE car_Client = {$OBJCTCL} AND car_Status IN (2,3,4,6)");
if (!isset($Ck_Card[1]['bac_Balance'])) {
    $Ck_Card[1]['bac_Balance'] = 0;
}
if ($Cliente[1]['CliNumero'] > 0) {
    $SliLock = '" disabled readonly="';
}
$SenderGeo = new Geo();
$GeoCountries = "SELECT geop.pai_CodElite AS ID, geop.pai_NombreESP AS NAME FROM hd_paises AS geop ORDER BY NAME ASC";
//============== VERIFY ENT:CL ================
// VERIfICA PASSPORTE E DOCUMENTOS CADUCADOS E BLOQUA CLIENTE CASO TRUE
//============== VERIFY ENT:CL:UPDATE DATA ================
echo $Client->ExpiredClientInfo($Cliente[1]);
//=====================Client Form=========================
form_pr('ClientProperties', '', '', 'post');
// ============= OBJECT & MAPS:CL ======================
mn_field('hidden', 'ED', 'OBJCTCL', $OBJCTCL, '', '', '', '');
mn_field('hidden', 'ED', 'CliMap', $Cliente[1]['CliMap'], '', '', '', '');
if ($Cliente[1]['CliFechaAlta'] == '') {
    $Cliente[1]['CliFechaAlta'] = ' ';
}
?>
<div class="title">
    <div>FICHA DE CLIENTE | <?php
    if ($OBJCTCL > 0) {
        if ($_POST['MDCLDT'] == 'True') {
            mn_field('button', 'ED', 'FMCLDT', 'Minimizar', '100', '38', '', 'SUBMIT"
                     onClick="document.ClientProperties.action=\'_response/call.php?get=Operative/view/viewsender\';
                     this.value=\'Maximizar\';subform(\'ClientProperties\',\'CL\');');
        } else {
            mn_field('button', 'ED', 'FMCLDT', 'Maximizar', '100', '38', '', 'SUBMIT"
                     onClick="document.ClientProperties.action=\'_response/call.php?get=Operative/view/viewsender\';
                     this.value=\'Minimizar\';subform(\'ClientProperties\',\'CL\');');
        }
    }
    mn_field('hidden', 'ED', 'MDCLDT', $_POST['MDCLDT'], '', '', '', '');
    if ($MDCL == 'RD' && $_SESSION[$SESSCD] == $Cliente[1]['CliOffice']) {
        mn_field('button', 'ED', 'MDCLED', 'Modificar', '12', '12', '', 'SUBMIT"
                    onClick="document.ClientProperties.action=\'_response/call.php?get=Operative/view/viewsender\';
                    subform(\'ClientProperties\',\'CL\');');
    } elseif ($MDCL == 'ED') {
        mn_field('button', 'ED', 'PRCLAB', 'Anular', '12', '12', '', 'SUBMIT"
                    onClick="subform(\'ClientProperties\',\'CL\');');
    }

    echo ' | '.rt_field('button', 'ED', 'CliPrint', 'Imprimir Ficha de Cliente', '', '', '', '" onclick="newprint(\'\',\'Printer\');').'
       | '.rt_field('date', 'ED', 'CliFechaAlta', $Cliente[1]['CliFechaAlta'], 'ClientProperties', '8', '', '').'
       | '.rt_field('text', 'ED', 'CliOffice', $Cliente[1]['OriNombre'], '40', '40', 'True', '" readonly="');?></div>
    <div style="float: right">| <?php
        mn_field('button', 'ED', 'selAgent', 'Agente', '', '', '', $SliLock . '" onclick="
		  idwindow(\'Agentes encontrados\',\'win_agent\',\'win_agent\',\'_response/call.php?get=Operative/view/viewsellers&Inp=\'+document.ClientProperties.cliAgent.value,400,180);');
        mn_field('text', 'ED', 'cliAgent', $Cliente[1]['sliSeller'], '', '', '', 'INPNUM' . $SliLock);?></div>
    <div id="CliTransfer" style="float:right"><?php
        if ($_SESSION[$SESSCD] != $Cliente[1]['CliOffice']) {
            mn_field('button', 'ED', 'CliTransfer', 'Associar a Balcão', '', '', '', '" onclick="
				document.ClientProperties.action=\'_response/call.php?get=Operative/clienttransfer\';
				subform(\'ClientProperties\',\'CliTransfer\');');
        }?></div>
</div>
<?php if ($Cliente[1]['CliBloqueado'] > 0) { ?>
            <div class="Error">Cliente Bloqueado</div>
<?php } ?>
<div id="MNCL" class="Line" style="width: 100%">
    <div style="float: left; width: 90px"><img id="PrfGfx" style="margin: 12px" src="" /> ARQ. <?php mn_field('text', 'ED', 'ClPhArc', '', '4', '4', '', '" disabled readonly="'); ?></div>
    <div style="float: left;"><?php
        if ($OBJCTCL > 0) {
            mn_field('text', 'ED', 'CliNumero', $Cliente[1]['CliNumero'], '10', '10', 'True', '" readonly="');
        } else {
            echo 'Nome completo do cliente';
        }
        echo '<br>'.rt_field('text', 'ED', 'CLName', $Cliente[1]['CliNombre'], '100', '76', '', $MD0 . '').'<br>';
?>
        <div id="Prf_Box" class="Line"><?php include('viewclientprofile.php'); ?></div>
        <div id="Prf_Alerts" class="Line"><?php
        if ($OBJCTCL > 0) {
            include('viewclientalerthistory.php');
        } ?></div>
        <div class="Line">Observações: <font color="#FF0000"><?php echo mn_field('text', $MDCL, 'ClObs', $Cliente[1]['ClObs'], '100', '50', 'True', ''); ?></font></div>
    </div>
    <div style="float: right; width: 300px"><?php
//================= Client Contact Box (Ctt) ==================
            if ($Cliente[1]['CLCttEmail'] == '0') {
                $frm_CliMailChecked = '" checked="checked';
                $Cliente[1]['CLCttEmail'] = '';
            } else {
                $frm_CliMailChecked = '';
            }
?>

            <div style="clear: both; width: 300px;">
                <div style="background-color: #BACCD1; height: 25px">
                    <div style="margin: 5px; float: left; font-weight: bold">Contactos</div>
                    <div style="float: right"><?php
            mn_field('hselect', 'ED', 'CliMailing', $Cliente[1]['CliMailing'], "Contactavel;Incontactavel#0;1", '', '', $MD0 . '" style="margin:3px');
            mn_field('text', 'ED', 'CliVal1', $Cliente[1]['CliDataVal1'], '17', '17', '', '" style="margin:3px; disabled readonly="');
?></div>
            </div>
            <div
                style="float: left; padding: 3px; width: 84px; background-color: #DFE8EA">Tel.
                Fixo</div>
            <div style="padding: 1px; float: left;"><?php echo mn_field('text', 'ED', 'CliTelefono', $Cliente[1]['CliTelefono'], '16', '16', '', $MD0 . ''); ?></div>
            <div
                style="clear: left; float: left; padding: 3px; width: 84px; background-color: #DFE8EA">Tel.
                M&oacute;vel</div>
            <div style="padding: 1px; float: left;"><?php echo mn_field('text', 'ED', 'CliTelefono2', $Cliente[1]['CliTelefono2'], '16', '16', '', $MD0 . ''); ?></div>
            <div
                style="clear: left; float: left; padding: 3px; width: 84px; background-color: #DFE8EA">Email
                (N/A<?php echo mn_field('checkbox', 'ED', 'CLCttEmailExists', '1', '', '', '', $MD0 . $frm_CliMailChecked); ?>)</div>
            <div style="padding: 1px; float: left;"><?php echo mn_field('text', 'ED', 'CLCttEmail', $Cliente[1]['CLCttEmail'], '50', '32', '', $MD0 . ''); ?></div>
            <div style="clear: left; width: 300px;">
                <?php
                    if (!isset($sys_isagent)) {
                        #Cartao de Pontos
                        include($GLOBALS['ROO'] . 'Modules/CartaoPontos/clientstatus.php');
                        #Promocoes
                        include('viewclientpromotions.php');
                    } ?>
                </div>
            </div>
    </div>
    <div id="Hist_Show" class="Line" style="clear: both"></div>
    <div id="MNDC" class="Line"><?php include('viewsenderdocument.php'); ?></div>
    <div id="CLADD" class="Line"><?php if ($_POST['MDCLDT'] == 'True') { ?>
                            <div id="CLAddress"
                                 style="float: left; padding: 5px; background-color: #BBCDD0">

                                <div style="margin: 3px; width: 290px; float: left"><?php echo $SenderGeo->GetCountry($Cliente[1]['ClPais'], 'ClPais', 'CliProvincia', 'CliCiudad', null, $Cliente[1]['CliProvincia'], 'GeoR', 'GeoCC', '', 'ED'); ?></div>
                                <div id="GeoR" style="margin: 3px; width: 200px; float: left"><?php echo $SenderGeo->GetRegion($Cliente[1]['CliProvincia'], 'CliProvincia', 'CliCiudad', $Cliente[1]['ClPais'], 0, 'GeoCC', 'ED'); ?></div>
                                <div id="GeoCC" style="margin: 3px; width: 260px; float: left;"><?php echo $SenderGeo->GetCity($Cliente[1]['CliCiudad'], 'CliCiudad', $Cliente[1]['CliProvincia'], $Cliente[1]['ClPais'], 'ED'); ?></div>
                                <br style="clear: both;" />
                                <div style="margin: 5px; float: left">Localidade:</div>
                                <div style="margin: 3px; float: left"><?php echo mn_field('text', 'ED', 'CliLocation', $Cliente[1]['CliLocation'], '50', '10', '', $MD0 . ''); ?></div>
                                <div style="margin: 5px; float: left">Cod.Postal:</div>
                                <div style="margin: 3px; float: left"><?php echo mn_field('text', 'ED', 'CliCP', $Cliente[1]['CliCP'], '8', '6', '', $MD0 . ''); ?></div>
                                <div style="margin: 5px; float: left">Morada:</div>
                                <div style="margin: 3px; float: left"><?php echo mn_field('text', 'ED', 'CliDomicilio', $Cliente[1]['CliDomicilio'], '100', '35', '', $MD0 . ''); ?></div>
                                <div style="margin: 5px; float: left">Numero</div>
                                <div style="margin: 3px; float: left"><?php echo mn_field('text', 'ED', 'CliPortal', $Cliente[1]['CliPortal'], '4', '1', '', $MD0 . ''); ?></div>
                                <div style="margin: 5px; float: left">Piso/Porta:</div>
                                <div style="margin: 3px; float: left"><?php echo mn_field('text', 'ED', 'CliPisoPuerta', $Cliente[1]['CliPisoPuerta'], '6', '1', '', $MD0 . ''); ?></div>
                            </div>
      <div id="CLNaturality" style="float: left; background-color: #BBCDD0">
          <table width="100%" cellpadding="0" cellspacing="2">
                <tr>
                    <td width="140" align="left">Naturalidade</td>
                    <td width="200" align="left"><?php mn_field('select', 'ED', 'CliNacionalidad', $Cliente[1]['CliNacionalidad'], $GeoCountries, '', '', $MD0 . '');?></td>
                    <td width="140">Data de Nascimento:</td>
                    <td width="200"><?php echo mn_field('date', 'ED', 'CliFechaNacimiento', $Cliente[1]['CliFechaNacimiento'], 'ClientProperties', '8', '', $MD0 . ''); ?></td>
                    <td width="60">Sexo:</td>
                    <td align="left"><?php mn_field('hselect', 'ED', 'CliGender', substr($Cliente[1]['CliMap'], 0, 1), "Masculino;Feminino#M;F", '', '', $MD0 . ''); ?></td>
                </tr>
                <tr>
                    <td align="left">Nacionalidade:</td>
                    <td align="left"><?php mn_field('select', 'ED', 'CliRes1', $Cliente[1]['CliRes1'], $GeoCountries, ' ', '', $MD0 . ''); ?></td>
                    <td>Nacionalidade Outra:</td>
                    <td colspan="3"><?php mn_field('select', 'ED', 'CliRes2', $Cliente[1]['CliRes2'], $GeoCountries, ' ', '', $MD0 . ''); ?></td>
                </tr>
                <tr>
                    <td align="left">Actividade</td>
                    <td align="left"><?php echo mn_field('text', 'ED', 'CliActividad', $Cliente[1]['CliActividad'], '50', '40', '', $MD0 . ''); ?></td>
                    <td>Tipo de Pessoa:</td>
                    <td colspan="3"><?php mn_field('hselect', 'ED', 'CliPerson', $Cliente[1]['CliPessoa'], "Fisica;Juridica#1;2", '', '', $MD0 . ''); ?>
                    </td>
                </tr>
                <tr>
                    <td>Conhecimento:</td>
                    <td colspan="4"><?php
                        $qr_conhecimento = "SELECT cnm_ID AS ID, cnm_Name AS NAME FROM systemoffice.comr_conhecimento WHERE cnm_Flag = 2 OR cnm_ID = {$Cliente[1]['CliConhecimento']}
						UNION SELECT 9999 AS ID, 'Outro' AS NAME FROM systemoffice.comr_conhecimento WHERE cnm_ID = 1";
                        $qr_conhgroup = "SELECT OriNumero AS ID, OriNombre AS NAME FROM Origenes WHERE OriTipo IN (1,2) AND OriActivo = 1 AND OriNumero > 800 ORDER BY OriNombre";
                        $qr_conhgroup2 = "SELECT cnm_Group AS ID, cnm_Name AS NAME FROM systemoffice.comr_conhecimento WHERE cnm_Comercial = 1";
                        if ($Cliente[1]['CliNumero'] > 0) {
                            $MDNEW = '" disabled readonly="';
                        } else {
                            $MDNEW = '';
                        }
                        mn_field('select', 'ED', 'CliConhecimento', $Cliente[1]['CliConhecimento'], $qr_conhecimento, ' ', '', $MD0 . $MDNEW . '" onChange="
					if(this.value==9999) {
						document.ClientProperties.CliConhecimento_Other.width=80;
						document.ClientProperties.CliConhecimento_Other.disabled=false;
						document.ClientProperties.CliConhecimento_Other.style.display=\'inline\';

									document.ClientProperties.CliConhecimento_Group.width=0;
									document.ClientProperties.CliConhecimento_Group.disabled=true;
									document.ClientProperties.CliConhecimento_Group.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group2.width=0;
									document.ClientProperties.CliConhecimento_Group2.disabled=true;
									document.ClientProperties.CliConhecimento_Group2.style.display=\'none\';

								} else if(this.value==11 || this.value==34 || this.value==48) {
									document.ClientProperties.CliConhecimento_Other.width=0;
									document.ClientProperties.CliConhecimento_Other.disabled=true;
									document.ClientProperties.CliConhecimento_Other.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group.width=80;
									document.ClientProperties.CliConhecimento_Group.disabled=false;
									document.ClientProperties.CliConhecimento_Group.style.display=\'inline\';

									document.ClientProperties.CliConhecimento_Group2.width=0;
									document.ClientProperties.CliConhecimento_Group2.disabled=true;
									document.ClientProperties.CliConhecimento_Group2.style.display=\'none\';
								} else if(this.value==188) {
									document.ClientProperties.CliConhecimento_Other.width=0;
									document.ClientProperties.CliConhecimento_Other.disabled=true;
									document.ClientProperties.CliConhecimento_Other.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group.width=0;
									document.ClientProperties.CliConhecimento_Group.disabled=true;
									document.ClientProperties.CliConhecimento_Group.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group2.width=80;
									document.ClientProperties.CliConhecimento_Group2.disabled=false;
									document.ClientProperties.CliConhecimento_Group2.style.display=\'inline\';
								} else {
									document.ClientProperties.CliConhecimento_Other.width=0;
									document.ClientProperties.CliConhecimento_Other.disabled=true;
									document.ClientProperties.CliConhecimento_Other.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group.width=0;
									document.ClientProperties.CliConhecimento_Group.disabled=true;
									document.ClientProperties.CliConhecimento_Group.style.display=\'none\';

									document.ClientProperties.CliConhecimento_Group2.width=0;
									document.ClientProperties.CliConhecimento_Group2.disabled=true;
									document.ClientProperties.CliConhecimento_Group2.style.display=\'none\';
								}');
                        mn_field('text', $MDCL, 'CliConhecimento_Other', '', '45', '45', '', '" style="display:none');
                        mn_field('select', $MDCL, 'CliConhecimento_Group', $_SESSION[$SESSCD], $qr_conhgroup, '', '', '" disabled style="display:none');
                        mn_field('select', $MDCL, 'CliConhecimento_Group2', '', $qr_conhgroup2, ' ', '', '" disabled style="display:none'); ?>

                        <?php
                        echo 'Funcionário Interno?';
                        mn_field('hselect', 'ED', 'CliInternal', substr($Cliente[1]['CliMap'], 7, 1), "Nao;Sim#0;1", '', '', $MD0 . '');

                        /*
                          echo 'Cliente Possui Voucher Amigo?';
                          mn_field('hselect','ED','CliVoucher',$VoucherSimNao,"Nao;Sim#0;1",'','',$MD0.'');
                          echo 'Nº de Voucher';
                          echo mn_field('text','ED','CliNumeroVoucher',$VoucherNumero,'15','10','',$MD0.'');
                         */
                        ?>




                    </td>
                </tr>
            </table>
        </div>
        <?php if ($MDCL == 'ED') {?>
        <div style="clear: both; background-color: #688F97; text-align: center">
            <?php echo mn_field('button', 'ED', 'PRCLSV2', 'Guardar', '12', '12', '', 'SUBMIT" onClick="
					document.ClientProperties.action=\'' . $action . '\';
					subform(\'ClientProperties\',\'CLMSG\');this.onClick=\'\';'); ?></div>
            <?php }
        } ?></div>
        </div>
</form>
<?php if (isset($_SESSION[$SESSST . 'ALT']) && $_SESSION[$SESSST . 'ALT'] == 1) { ?>
<script charset="utf-8" type="text/javascript">if(confirm('Tem comunicados por ler. Deseja ler agora?')==true){replaceUrl('app','_response/call.php?get=HelpCenter/mho');}</script>
<?php }
if($OBJCTCL==0 || $MDCL != 'RD'){die();}?>
<div id="ClientProp" class="Line" style="width:100%">
<?php if($_SESSION[$SESAMD] == "XFK0WK2A") {require($GLOBALS['ROO'] . "Modules/Operative/receiver.php");} elseif ($_SESSION[$SESAMD] == "MX23DF2S") {include($GLOBALS['ROO'] . "Modules/Exchange/app.makeorder.php");}?>
</div>